package com.wskj.common.constant;

import com.wskj.common.config.RuoYiConfig;
import com.wskj.common.utils.spring.SpringUtils;

/**
 * REDIS通用常量信息
 *
 * @author ruoyi
 */
public class RedisConstants {
    /**
     * 验证码 redis key
     */
    public static final String CAPTCHA_CODE_KEY = RedisConstants.getRedisKey("captcha_codes:");

    /**
     * 登录用户 redis key
     */
    public static final String LOGIN_TOKEN_KEY = RedisConstants.getRedisKey("login_tokens:");

    /**
     * 登录用户 记录当前用户userId对应uuid
     */
    public static final String LOGIN_USERID_KEY =  RedisConstants.getRedisKey("login_userId:");

    /**
     * 防重提交 redis key
     */
    public static final String REPEAT_SUBMIT_KEY = RedisConstants.getRedisKey("repeat_submit:");

    /**
     * 参数管理 cache key
     */
    public static final String SYS_CONFIG_KEY = RedisConstants.getRedisKey("sys_config:");

    /**
     * 字典管理 cache key
     */
    public static final String SYS_DICT_KEY = RedisConstants.getRedisKey("sys_dict:");

    /**
     * 资源映射路径 前缀
     */
    public static final String REDIS_LOCK_KEY = RedisConstants.getRedisKey("redis_lock:");

    /**
     * ip地址
     */
    public static final String SMS_IP_ADDRESS_KEY = RedisConstants.getRedisKey("sms_ip_address:");

    /** 验证码 参数key */
    public static final String SMS_AUTH_CODE= RedisConstants.getRedisKey("sms_auth_code:");

    /**
     * 短信 key
     */
    public static final String SMS_TIMES_KEY = RedisConstants.getRedisKey("sms_times:");

    /**
     * 同一个ip获取验证码次数{手机验证码}
     */
    public static final String SMS_AUTH_CODE_MAX_NUM = RedisConstants.getRedisKey("sys_config","sms_auth_code_max_num:");

    /**
     * 同一个ip获取验证码，过期时间，24小时{手机验证码}
     */
    public static final String SMS_EXPIRE_HOUR = RedisConstants.getRedisKey("sys_config","sms_expire_hour:");

    /**
     * 过期时间，5分钟{手机验证码}
     */
    public static final String SMS_EXPIRE_MINUTE = RedisConstants.getRedisKey("sys_config","sms_expire_minute:");

    /**
     * 手机验证码开关,默认或者真实
     */
    public static final String SMS_SWITCH = RedisConstants.getRedisKey("sys_config","sms_switch:");

    /**
     * 医生-机构端-提现加锁
     */
    public static final String WITHDRAW_USERID = RedisConstants.getRedisKey("withdraw:userid:");


    /**
     * 获取redis key值
     * @param values
     * @return
     */
    public static String getRedisKey(String ...values){
        StringBuffer redisKey = new StringBuffer();
        // 项目名称
        String projectName = SpringUtils.getBean(RuoYiConfig.class).getAliasName();
        redisKey.append(projectName);
        for(String value : values){
            redisKey.append(":");
            redisKey.append(value);
        }
        return redisKey.toString();
    }
}
